import request from "@/utils/request";

const USER_BASE_URL = "/core/vehicle";

const vehicleSchedulingApi = {
  //分页查询车辆调度信息
  getVehicleMonitoring: (params: vehicleSchedulingQuery) => {
    let query = encodeURIComponent(JSON.stringify(params));
    return request<vehicleSchedulingQuery, vehicleScheduling[]>({
      url: `${USER_BASE_URL}/info/query?object=${query}`,
      method: "get",
    });
  },
  //统计各配送状态数量
  getVehicleMonitoringCount: () => {
    return request<null, VehicleMonitoringCount>({
      url: `${USER_BASE_URL}/info/delivery/count`,
      method: "get",
    });
  },
  //新增外部车辆
  addExternalVehicle: (params: ExternalVehicle) => {
    return request<ExternalVehicle, any>({
      url: `${USER_BASE_URL}/info/external/add`,
      method: "post",
      data: params,
    });
  },
  //查询车辆调度信息
  queryVehicleInfo: (params: VehicleMonitoringQuery): Promise<VehicleMonitoringResult> => {
    let query = encodeURIComponent(JSON.stringify(params));
    return request({
      url: `${USER_BASE_URL}/info/queryVehicleInfo?object=${query}`,
      method: "get",
    });
  },
  //删除
  deleteVehicle: (id: number) => {
    return request<string, any>({
      url: `${USER_BASE_URL}/info/delete/${id}`,
      method: "post",
    });
  },
};
export default vehicleSchedulingApi;

//查询车辆调度信息请求参
export interface VehicleMonitoringQuery {
  vehicleId?: string;
  lockStatus?: string;
  temperature?: string;
}
// 查询车辆调度信息响应接口
export interface VehicleMonitoringResult {
  latitude: string;
  lockStatus: string;
  longitude: string;
  speed: string;
  temperature: string;
  timestamp: string;
  vehicleId: string;
}

// 车辆监控信息查询接口
export interface vehicleSchedulingQuery extends PageQuery {
  /**
   * 车牌号
   */
  licensePlate?: string;

  /**
   * 司机姓名
   */
  driverName?: string;
  /**
   * 配送状态
   */
  deliveryStatus?: number;
}

export interface vehicleScheduling {
  contactInfo: string;
  createName: string;
  createTime: string;
  createUser: string;
  driverName: string;
  id: number;
  isDelete: number;
  isExternalVehicle: number;
  licensePlate: string;
  modifyName: string;
  modifyTime: string;
  modifyUser: string;
  remark: string;
  vehicleInfoDTOList?: TaskItem[];
  vehicleStatus: number;
}

export interface TaskItem {
  contactPerson: string; //联系人姓名
  contactPhone: string; //联系人电话
  saleCode: string; //销售单号
  address: string; //送货地址
  shipDate: string; //发货日期
  shipOrderCode: string; //发货单编号
  status: number; //配送状态
}

/**
 * 外部车辆
 */
export interface ExternalVehicle {
  /**
   * 车牌号
   */
  licensePlate: string;

  /**
   * 司机姓名
   */
  driverName: string;
  /**
   * 联系电话
   */
  contactInfo: string;
  /**
   * 备注信息
   */
  remark: string;
  isExternalVehicle: number; // 状态
}

//统计各配送状态数量
export interface VehicleMonitoringCount {
  completedCount: number; // 已完成数量
  deliveringCount: number; // 配送中数量
  pendingCount: number; // 待配送数量
  totalCount: number; // 总数
}
